package cn.javadog.algorithm.e601_1000;

import java.util.ArrayList;
import java.util.List;


/**
 * 较大分组的位置
 * https://leetcode-cn.com/problems/positions-of-large-groups/
 * @author Sprite
 */
public class Algorithm830 {

	public static void main(String[] args) {
		String s = "aaa";
		List<List<Integer>> lists = largeGroupPositions(s);
		System.out.println(lists);
	}

	public static List<List<Integer>> largeGroupPositions(String S) {
		List<List<Integer>> lists = new ArrayList<>();
		char[] chars = S.toCharArray();
		int start_index = 0;
		int len = 0;
		char c = chars[0];
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] == c){
				len++;
			}else {
				if (len>2){
					List<Integer> list = new ArrayList<>();
					list.add(start_index);
					list.add(start_index+len-1);
					lists.add(list);
				}
				len = 1;
				start_index = i;
				c = chars[i];
			}
		}
		if (len>2){
			List<Integer> list = new ArrayList<>();
			list.add(start_index);
			list.add(start_index+len-1);
			lists.add(list);
		}
		return lists;
	}
}

